package jsyf.oa.service.wreport;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.fastjson.JSONObject;
import jsyf.com.dao.BaseJdbcDao;
import jsyf.oa.dao.wreport.User2WreportDao;
import jsyf.oa.entity.report.User2ReportEntity;
import jsyf.oa.entity.wreport.User2WreportEntity;
import jsyf.oa.facade.wreport.WreportModuleFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Lenovo on 2017/12/11.
 */
@Service
@Transactional(rollbackFor = Exception.class)
@com.alibaba.dubbo.config.annotation.Service(protocol = {"dubbo"})
public class WreportModuleService implements WreportModuleFacade {
    @Autowired
    private User2WreportDao dao;
    @Override
    public Boolean config(String userId, String moduleIds) {
        dao.removeByCondition(" AND USER_ID = ? ",new String[]{userId});
        if (!StringUtils.isEmpty(moduleIds)) {
            List<String> list = BaseJdbcDao.stringToList(moduleIds);
            for (int i = 0; i < list.size(); i++) {
                User2WreportEntity entity = new User2WreportEntity();
                entity.setUserId(userId);
                entity.setModuleId(list.get(i));
                dao.add(entity);
            }
        }
        return true;
    }
    @Override
    public List<JSONObject> getByUserId(String userId) {
        return dao.getJSONListByCondition(" AND USER_ID = ? ",new Object[]{userId});
    }
}
